package com.settlement.system.service.impl;

import com.settlement.system.model.entity.SysDoneAuditNoLink;
import com.settlement.system.mapper.SysDoneAuditNoLinkMapper;
import com.settlement.system.service.SysDoneAuditNoLinkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.model.query.SysDoneAuditNoLinkQuery;
import com.settlement.system.model.form.SysDoneAuditNoLinkForm;
import cn.hutool.core.bean.BeanUtil;
import com.settlement.system.model.vo.SysDoneAuditNoLinkImportVo;

/**
 * <p>
 * 个人核销表与待核销对应关系 服务实现类
 * </p>
 *
 * @author huangrensen
 * @since 2024-05-16
 */
@Service
public class SysDoneAuditNoLinkServiceImpl extends ServiceImpl<SysDoneAuditNoLinkMapper, SysDoneAuditNoLink> implements SysDoneAuditNoLinkService {

    @Override
    public Page<SysDoneAuditNoLink> getPage(SysDoneAuditNoLinkQuery queryParams) {
        // 查询参数
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        // 查询数据
        Page<SysDoneAuditNoLink> page = new Page<>(pageNum, pageSize);
        return this.baseMapper.getPage(page, queryParams);
    }

     @Override
     public boolean saveSysDoneAuditNoLink(SysDoneAuditNoLinkForm sysDoneAuditNoLinkForm) {
         SysDoneAuditNoLink sysDoneAuditNoLink = new SysDoneAuditNoLink();
         BeanUtil.copyProperties(sysDoneAuditNoLinkForm, sysDoneAuditNoLink);
         return this.saveOrUpdate(sysDoneAuditNoLink);
     }

     @Override
     public SysDoneAuditNoLinkForm getSysDoneAuditNoLinkFormData(Long id) {
         SysDoneAuditNoLink sysDoneAuditNoLink = this.getById(id);
         SysDoneAuditNoLinkForm sysDoneAuditNoLinkForm = new SysDoneAuditNoLinkForm();
         BeanUtil.copyProperties(sysDoneAuditNoLink, sysDoneAuditNoLinkForm);
         return sysDoneAuditNoLinkForm;
     }

     @Override
     public boolean deleteSysDoneAuditNoLink(String ids) {
        Assert.isTrue(StrUtil.isNotBlank(ids), "删除的数据为空");
        List<Long> idArray = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
        return this.removeByIds(idArray);
     }

    @Override
    public void importData(List<SysDoneAuditNoLinkImportVo> voList)  {
        List<SysDoneAuditNoLink> sysDoneAuditNoLinkList = new ArrayList<>();
        for (SysDoneAuditNoLinkImportVo importVo : voList) {
            SysDoneAuditNoLink sysDoneAuditNoLink = new SysDoneAuditNoLink();
            BeanUtil.copyProperties(importVo, sysDoneAuditNoLink);
            sysDoneAuditNoLinkList.add(sysDoneAuditNoLink);
        }
        this.saveOrUpdateBatch(sysDoneAuditNoLinkList);
    }

    @Override
    public List<SysDoneAuditNoLinkImportVo> findByIds(String idsStr) {
        if (StrUtil.isBlank(idsStr)) {
            return new ArrayList<>();
        }
        List<Long> ids = Arrays.stream(idsStr.split(",")).map(Long::parseLong).collect(Collectors.toList());
        List<SysDoneAuditNoLink> sysDoneAuditNoLinkList = this.getBaseMapper().selectBatchIds(ids);
        List<SysDoneAuditNoLinkImportVo> voList = new ArrayList<>();
        for (SysDoneAuditNoLink sysDoneAuditNoLink : sysDoneAuditNoLinkList) {
            SysDoneAuditNoLinkImportVo vo = new SysDoneAuditNoLinkImportVo();
            BeanUtil.copyProperties(sysDoneAuditNoLink, vo);
            voList.add(vo);
        }
        return voList;
    }
}
